package cn.com.fattiger.object.clone;

import java.io.Serializable;

import org.springframework.util.SerializationUtils;

public class ApacheCloneDemo implements Cloneable,Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String name;
	private ApacheCloneChild cloneChild;
	public ApacheCloneDemo(int id,ApacheCloneChild cloneChild){
		this.cloneChild = cloneChild;
		this.id = id;
	}
	public static void main(String[] args) throws CloneNotSupportedException{
		ApacheCloneChild cc = new ApacheCloneChild(2);
		ApacheCloneDemo cd = new ApacheCloneDemo(1,cc);
		cd.setApacheCloneChild(cc);
		ApacheCloneDemo cdc = (ApacheCloneDemo) cd.clone();
		cdc.getApacheCloneChild().setId(333);
		ApacheCloneDemo ac = (ApacheCloneDemo) SerializationUtils.deserialize(SerializationUtils.serialize(cd));
		ac.getApacheCloneChild().setId(444);
		System.out.println(cdc.getApacheCloneChild().getId());
		System.out.println(cd.getApacheCloneChild().getId());
		System.out.println(ac.getApacheCloneChild().getId());
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public ApacheCloneChild getApacheCloneChild() {
		return cloneChild;
	}
	public void setApacheCloneChild(ApacheCloneChild cloneChild) {
		this.cloneChild = cloneChild;
	}
	
}
class ApacheCloneChild implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 6077634051447392957L;
	private int id;
	private String name;
	public ApacheCloneChild(int id){
		this.id =id;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
}
